package com.accp.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.accp.pojo.Room;
import com.accp.service.RoomService;
import com.accp.service.impl.RoomServiceImpl;


@Controller
public class GMRoomController {
	
	@Autowired
	RoomService roomService =new RoomServiceImpl();
	
	
	@RequestMapping("/GMgetAllRoom")
	public String getAllRomm(Model model){
		
		List<Room> room=roomService.getAllRoom();
		
		for (Room room1 : room) {
			System.out.println(room1.getRoomtypename());
		}
		
		model.addAttribute("room", room);
		
		return "GMRoom";
	}
	
	
	
	@RequestMapping("deleteRoom")
	public String deleteRoom(int roomid){
		
		
		System.out.println("id"+roomid);
		
		
		try {
			
		
		
		int result=roomService.deleteByPrimaryKey(roomid);
		
		if (result==1) {
			
			System.out.println("删除成功");
			
			return "redirect:GMgetAllRoom";
			
		}
		} catch (Exception e) {
			
			System.out.println("删除失败");
			return "deleteRoomFailed";
			
		}
	
		
		return "";
		
	}
	
	
	@RequestMapping("/getRoomByState")
	public String getRoomByState(Integer roomState,Model model){
		
		
		System.out.println("id"+roomState);
		
		List<Room> room=roomService.getByState(roomState);
		
		
		for (Room room2 : room) {
			System.out.println(room2.getRoomtypename());
		}
		
		model.addAttribute("room2", room);
		
		return "GMRoom";
	}
	
	@RequestMapping("toUpdateRoom")
	public String toUpdateRoom(){
		
		
		
		return "GMupdateRoom";
	}
	
	
	
	@RequestMapping("getRoomById")
	public String getRoomById(int roomid){
		
		
		
		
		
		
		return "";
	}
	
	
}
